//
//  SettingViewController.m
//  Atlantis
//
//  Created by 何恩营 on 14-12-17.
//  Copyright (c) 2014年 lanou3g.com 蓝鸥科技. All rights reserved.
//

// 设置页面
#import "SettingViewController.h"
#import "AboutUsViewController.h"
#import "SDImageCache.h"
#import "UIColor+AddColor.h"
@interface SettingViewController ()

@end

@implementation SettingViewController

- (void)viewWillAppear:(BOOL)animated
{
    // 始终空出导航栏的高度
    self.navigationController.navigationBar.translucent = NO;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    // 导航栏标题
    self.navigationItem.title = @"设置";
    
   
    // 清理缓存 -_- 按钮
    // 创建按钮
    UIButton *cacheButton = [UIButton buttonWithType:UIButtonTypeSystem];
    // 设置按钮的大小
    cacheButton.frame = CGRectMake(5, 20, self.view.bounds.size.width - 10, 50);
    // 按钮背景颜色
    cacheButton.backgroundColor = [UIColor colorFromHexCode:@"#e6e6e6"];
    // 按钮文字
    [cacheButton setTitle:@"清理缓存" forState:UIControlStateNormal];
    // 设置按钮文字大小
    cacheButton.titleLabel.font = [UIFont fontWithName:nil size:20];
    // 按钮文字颜色
    cacheButton.tintColor = [UIColor blackColor];
    // 按钮触发事件
    [cacheButton addTarget:self action:@selector(cacheButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    // 将视图加载到这个页面视图上
    [self.view addSubview:cacheButton];
    
    

    // 关于按钮
    // 创建按钮
    UIButton *aboutButton = [UIButton buttonWithType:UIButtonTypeSystem];
    // 设置按钮大小
    aboutButton.frame = CGRectMake(5, 80, self.view.bounds.size.width - 10, 50);
    // 按钮背景颜色
    aboutButton.backgroundColor = [UIColor colorFromHexCode:@"#e6e6e6"];
    // 按钮文字
    [aboutButton setTitle:@"关于" forState:UIControlStateNormal];
    // 按钮文字大小
    aboutButton.titleLabel.font = [UIFont fontWithName:nil size:20];
    // 按钮文字颜色
    aboutButton.tintColor = [UIColor blackColor];
    // 按钮触发事件
    [aboutButton addTarget:self action:@selector(aboutUsButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    // 将视图加载到这个页面视图上
    [self.view addSubview:aboutButton];
    
    
    //self.tabBarController.tabBarItem = [[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemRecents tag:100] autorelease];
    

    
    // 导航栏左侧返回按钮
    self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"return.png"] style:UIBarButtonItemStyleDone target:self action:@selector(collectionAction:)] autorelease];
    
    
    
}


// 导航栏左侧返回按钮触发事件
- (void)collectionAction:(UINavigationBar *)bar
{
    //NSLog(@"返回前一页");
    // 推出前一页
    [self.navigationController popViewControllerAnimated:YES];
}





// 清除图片缓存按钮的实现方法
- (void)cacheButtonClicked:(UIButton *)cacheButtton
{
    // 清理图片缓存
    NSLog(@"清理图片缓存");
    // 定义一个float类型的变量 size , 表示可清理的图片所占空间大小
    float size = [[SDImageCache sharedImageCache] checkTmpSize];
    // 调用方法, 清理图片内存
    [[SDImageCache sharedImageCache] clearDisk];
    NSString *str = [NSString stringWithFormat:@"缓存清除成功, 大小为%.2fMB", size];
    // 创建警告视图, 提示清理图片大小
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:str delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
    // 调用show方法, 显示alertView
    [alertView show];
    // alertView的内存释放
    [alertView release];

}

// 关于按钮的实现方法
- (void)aboutUsButtonClicked:(UIButton *)aboutUsButton
{
    // 进入关于我们界面
    NSLog(@"进入关于我们界面");
    // 创建关于我们视图控制器
    AboutUsViewController *aboutUsVC = [[AboutUsViewController alloc] init];
    // push推出关于我们页面
    [self.navigationController pushViewController:aboutUsVC animated:YES];
    // 释放内存
    [aboutUsVC release];
 
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
